package cq.zhcqk.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import java.util.Map;

import cq.zhcqk.R;
import cq.zhcqk.activity.LoginActivity;
import cq.zhcqk.app;

/**
 * Created by zhangle on 2017/11/28.
 */
public class CheckLogin {
    public static void checkLogin(Context context,String res){
        if(res == null || "".equals(res)){
            return;
        }
        Map<String, Object> map = GsonUtil.GsonToMaps(res+"");
        if(map != null){
            String code = map.get("code")+"";
            if("301.0".equals(code)){
                Toast.makeText(context,"请先登录",Toast.LENGTH_SHORT).show();
                context.startActivity(new Intent(context, LoginActivity.class));
            }
        }

    }

    public static void checkLoginByState(Context context, Activity activity){
        if(!app.isLogin){
            Toast.makeText(context,"请先登录",Toast.LENGTH_SHORT).show();
            context.startActivity(new Intent(context, LoginActivity.class));
            activity.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
            return;
        }
    }
}
